<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" action="/admin/department" method="get" >
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name"  placeholder="请输单位名字" autocomplete="off" value="{{.name}}" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加单位','/admin/department/create',600,500)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>单位名称</th>
                            <th>单位代码</th>
                            <th>排序</th>
                            <th>加入时间</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                        {{range .list}}
                            <tr>
                                <td>{{.Id}}</td>
                                <td>{{.Name}}</td>
                                <td>{{.Code}}</td>
                                <td>{{.Sort}}</td>
                                <td>{{date .CreatedAt "Y-m-d H:i:s"}}</td>
                                <td class="td-manage">
                                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑单位','/admin/department/edit/{{.Id}}',600,450)" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                    <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="del(this,{{.Id}})" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                </td>
                            </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    {{str2html .paginator}}
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            type: 'datetime'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end', //指定元素
            type: 'datetime'
        });

        /*用户-停用*/
        form.on('switch(status)', function (obj) {
            var id = $(this).data('id')
            request_post('/admin/sys/update_status',{id:id}).then(function (data) {
                //设置成功
            },function (error) {
                msg_error(error.msg)
            })

        });
    })
    /*删除*/
    function del(obj,id){
        layer.confirm("确认要执行此操作吗？",function(index){
            request_get('/admin/department/destroy/'+id).then(function (data) {
                $(obj).parents("tr").remove();
            },function (error) {
                msg_error(error.msg)
            })
            layer.close(index)
        })
    }
</script>
